package com.sxhuayuan.parking.service.impl;

import javax.annotation.Resource;

import com.sxhuayuan.parking.service.QueueMsgSubmitService;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.alibaba.fastjson.JSON;
import com.sxhuayuan.parking.compenent.RabbitMQConfig;
import com.sxhuayuan.parking.entity.Order;
import com.sxhuayuan.parking.entity.ParkingIn;
import com.sxhuayuan.parking.queue.QueueService;
import com.sxhuayuan.parking.queue.msg.NotifyParkingLotMsg;
import com.sxhuayuan.parking.queue.msg.QueueMsg;

@Component("queueMsgSubmitServiceImpl")
public class QueueMsgSubmitServiceImpl implements QueueMsgSubmitService {

	@Resource(name = "rabbitMsgQueue")
	QueueService service;

	@Override
	public void submitNotifyParkingLotMsg(ParkingIn in, Order order) {
		Assert.notNull(order, "order can't be null");
		QueueMsg queueMsg = new QueueMsg();
		queueMsg.setTopic(RabbitMQConfig.QUEUE_DELAY_NOTIFY_PARKING_LOT);
		queueMsg.setDelayTime(0);
		queueMsg.setRetryPlan(NotifyParkingLotMsg.RETRY_PLAN);
		queueMsg.setRetryTimes(0);
		NotifyParkingLotMsg body = new NotifyParkingLotMsg(order.getPluginId(), order.getSn(), order.getParkingLotSn(), order.getCarPlate(), in.getLotRecordId());
		queueMsg.setBody(JSON.toJSONString(body));
		service.push(queueMsg);
	}
}
